import 'package:flutter/material.dart';

class GridViewExtendWidget extends StatelessWidget {
  const GridViewExtendWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.amber,
        title: const Text('案例-GridViewExtend'),
      ),
      body: GridView.extent(
        // 设置测轴方向子元素宽度, 此时每行展示的子元素个数是变化的
        maxCrossAxisExtent: 100,
        mainAxisSpacing: 10,
        crossAxisSpacing: 5,
        childAspectRatio: 1.0,
        children: [
          Container(
            color: Colors.red,
            alignment: Alignment.center,
            child: Text("我学习我无敌"),
          ),
          Container(
            color: Colors.blue,
            alignment: Alignment.center,
            child: Text("我学习我牛逼"),
          ),
          Container(
            color: Colors.brown,
            alignment: Alignment.center,
            child: Text("我学习我不愚"),
          ),
          Container(
            color: Colors.cyan,
            alignment: Alignment.center,
            child: Text("我学习去去去"),
          ),
          Container(
            color: Colors.deepPurpleAccent,
            alignment: Alignment.center,
            child: Text("我学习怕个屁"),
          ),
          Container(
            color: Colors.green,
            alignment: Alignment.center,
            child: Text("我学习专干你"),
          ),
        ],
      ),
    );
  }
}
